package com.anntly.nio.demo;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @Auther: 张文
 * @Date: 2020/5/3 16:35
 * @Description:
 */
public class Client {

    public static void main(String[] args) throws IOException {
        InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 6666);
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);
        if(!socketChannel.connect(inetSocketAddress)){
            while (!socketChannel.finishConnect()){
                System.out.println("connecting  do something");
            }
        }
        String msg = "hello";
        ByteBuffer wrap = ByteBuffer.wrap(msg.getBytes());
        // 发送数据
        socketChannel.write(wrap);
        System.in.read();
    }
}
